import time

from selenium.webdriver.common.by import By
from UItest.elem import Creat_Elems
from UItest.common.basepage import BasePage
from selenium.webdriver import ActionChains, Chrome#新增购货单操作需要的
from selenium.webdriver.support.select import Select

class CreatPage(BasePage):

    def __init__(self, driver: Chrome):
        self.driver = driver


    def creat_anniu(self):
        self.click(Creat_Elems.xiangmuzhongxin_locator)
        self.click(Creat_Elems.Creat_locator)
        return self
    # def inifram(self):
    #     self.switch_to_frame(Purchase_goodElems.Purchase_orderifram_locator)
    #     return self

    def Add_new_xiangmu(self,):
        ac = ActionChains(self.driver)
        ac.double_click(self.driver.find_element(By.XPATH, "//tr[@id='nod_1']//td[6]")).send_keys("小米14").perform()
        self.driver.find_element(By.XPATH, "//button[contains(text(),'新增单据')]").click()
        self.driver.find_element(By.XPATH, "//td[contains(text(),'点击选择')]").click()
        s = self.driver.find_element(By.XPATH, "//select[@id='1_attr']")
        S_obj = Select(s)
        S_obj.select_by_visible_text("黑色")
        # 获取购货金额做实际金额和实付金额的输入值，就不自己乱取了,xpath相对定位有两个，换成了绝对定位有点长
        Purchase_amount = self.driver.find_element(By.XPATH,
                                              "/html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[3]/div[4]/div[1]/table[1]/tbody[1]/tr[2]/td[13]").text
        time.sleep(1)
        self.driver.find_element(By.XPATH, "//input[@id='actual']").send_keys(Purchase_amount)
        self.driver.find_element(By.XPATH, "//input[@id='money']  ").send_keys(Purchase_amount)
        time.sleep(1)
        self.driver.find_element(By.XPATH, "//tip[contains(text(),'请选择结算账户')]").click()
        self.driver.find_element(By.XPATH, "//dd[contains(text(),'周嘉彤')]").click()
        self.driver.find_element(By.XPATH, "//tip[contains(text(),'请选择供应商')]").click()
        self.driver.find_element(By.XPATH, "//dd[contains(text(),'蓝星科技有限公司')]").click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, "//button[contains(text(),'新增单据')]").click()
        self.driver.switch_to.parent_frame()
        ifram1 = self.driver.find_element(By.XPATH, "/html/body/div/div/div[4]/div[2]/iframe")
        self.driver.switch_to.frame(ifram1)
        return self